package com.aurora.app.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.aurora.app.dao.HelpCommentDao;
import com.aurora.app.dao.ThingCommentDao;
import com.aurora.app.entity.ThingComment;
import com.aurora.app.entity.Help;
import com.aurora.app.entity.HelpComment;
import com.aurora.app.entity.Thing;
import com.aurora.app.enums.UtTsType;
import com.aurora.base.dao.BaseDao;
import com.aurora.base.dto.Order;
import com.aurora.base.dto.QueryResult;
import com.aurora.base.service.BaseService;
@Service
public class HelpCommentService extends BaseService<HelpComment> {

	@Resource
	private HelpCommentDao baseDao;
	
	@Override
	public BaseDao<HelpComment> getBaseDao() {
		// TODO 自动生成的方法存根
		return this.baseDao;
	}
	
	/**
	 * 获取闲置物品的评论
	 * @param thingId
	 * @return
	 */
	public List<HelpComment> getListByHelp(String helpId){
		return this.baseDao.list("o.help.id = ? and o.isDelete = 0", helpId);
	}
	
	/**
	 * 获取闲置物品的评论
	 * @param thingId
	 * @return
	 */
	public QueryResult<HelpComment> getListByHelpByPages(String helpId,int firstResult,int maxResults){
		Order order = new Order();
		order.put("createTime", Order.DESC);
		return this.baseDao.query(order,firstResult,maxResults,"o.help.id = ? and o.isDelete = 0", helpId);
	}
	
	/**
	 * 获取物品的评论数量
	 * @param thing
	 * @return
	 */
	public long getCommentNum(Help help){
		return this.baseDao.getCount("o.help = ?  and o.isDelete = 0", help);
	}
	
	
	/**
	 * 添加一条评论
	 * @param comment
	 * @return
	 */
	@Transactional
	public boolean addComment(HelpComment comment){
		this.baseDao.persist(comment);
		return true;
	}
	
}
